/**
 * Created by Administrator on 2015/11/30.
 */
function Shape(){}
Shape.prototype.area = function(){
    console.log('Shape area function is invoked');
};
Shape.prototype.draw = function(){}




function Rectangle(x,y,width,height){
    this.x = x;
    this.y = y;
    this.width = width;
    this.height = height;
}
Rectangle.prototype = Object.create(Shape.prototype);
//Rectangle.prototype = Shape.prototype;
//如果按照上面这种写法其实也是可以的，但是有个问题
//如果Circle也这么写，那么如果对area函数进行重载
//会对所有继承于Shape的对象使用area造成改写，这不是我们想要的结果
//所以这里都是使用独立的对象实例来继承
Rectangle.prototype.area = function(){
    return this.width * this.height;
}
function Circle(x,y,radius){
    this.x = x;
    this.y = y;
    this.radius = radius;
}
Circle.prototype = Object.create(Shape.prototype);
Circle.prototype.area = function(){
    return 2*Math.PI*this.radius;
}

var r = new Rectangle(0,0,10,10);
console.log(r.area());
r.area();
var c = new Circle(0,0,10);
console.log(c.area());

console.log(r instanceof Rectangle);//true
console.log(r instanceof Shape);//true
console.log(c instanceof Circle);//true
console.log(c instanceof Shape);//true
console.log(Object.getPrototypeOf(c));//Shape {area: [Function] }
console.log(Object.getPrototypeOf(r));//Shape {area: [Function] }
console.log(Object.getPrototypeOf(c) === Object.getPrototypeOf(r));//false
console.log(Circle.prototype.constructor);